package com.dzl.goods.service.impl;

import com.dzl.base.service.BaseServiceImpl;
import com.dzl.goods.dao.WelfareGoodsCategoryRelMapper;
import com.dzl.goods.pojo.WelfareGoodsCategoryRel;
import com.dzl.goods.service.WelfareGoodsCategoryRelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 集采商品品类表(WelfareGoodsAndLabel)表服务实现类
 * @author liuguanjun
 * @date 2021-12-16 11:48:08
 */
@Service
public class WelfareGoodsCategoryRelServiceImpl extends BaseServiceImpl<WelfareGoodsCategoryRel> implements WelfareGoodsCategoryRelService {

    @Autowired
    private WelfareGoodsCategoryRelMapper mapper;


    @Override
    public List<WelfareGoodsCategoryRel> selectGoodsCategoryRelByGoodsId(Integer goodsId) {
        return mapper.selectGoodsCategoryRelByGoodsId(goodsId);
    }

    @Override
    public Integer saveGoodsCategoryRel(Integer categoryId,String goodsIds) {
        //保存新的关联关系
        String[] ids = goodsIds.split(",");
        List<WelfareGoodsCategoryRel> list = new ArrayList<>();
        for (String id:ids) {
            WelfareGoodsCategoryRel welfareGoodsCategoryRel = new WelfareGoodsCategoryRel();
            welfareGoodsCategoryRel.setCategoryId(categoryId);
            welfareGoodsCategoryRel.setGoodsId(Integer.valueOf(id));
            list.add(welfareGoodsCategoryRel);
        }
        int result = mapper.insertList(list);
        return result;
    }

    @Override
    public Integer deleteCategoryRelGoods(Integer categoryId,Integer goodsId) {
        WelfareGoodsCategoryRel welfareGoodsCategoryRel = new WelfareGoodsCategoryRel();
        welfareGoodsCategoryRel.setCategoryId(categoryId);
        welfareGoodsCategoryRel.setGoodsId(goodsId);
        int result = mapper.delete(welfareGoodsCategoryRel);
        return result;
    }


}